package com.syc.sss.interceptor;

import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class LoginInterceptor implements HandlerInterceptor {

    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        String username = (String)request.getSession().getAttribute("username");
        String password = (String)request.getSession().getAttribute("password");
        if(username == null || !"admin".equals(username) || !"admin".equals(password)){
            response.sendRedirect("/login");
            return false;
        }
        return true;
    }
}
